home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
Alpha ƒ
/
Tcl
/
SystemCode
/
latexSmart.tcl
< prev
next >
Wrap
Text File
|
1996-01-15
|
4KB
|
178 lines
#############################################################################
#############################################################################
#
# latexSmart.tcl (called from latex.tcl)
#
# Smart quotes, dots, subscripts, and superscripts
#
#############################################################################
#
# Original author unknown
#
# Maintainer: Tom Scavo <trscavo@syr.edu>
#
#############################################################################
#############################################################################
#--------------------------------------------------------------------------
# Smart quotes:
#--------------------------------------------------------------------------
proc smartDQuote {} {
global TeXmodeVars
if {[isSelection]} { deleteSelection }
if { !$TeXmodeVars(smartQuotes) || [literalChar] } { insertText {"}; return }
if {[leftQ]} {
insertText {``}
} else {
insertText {''}
}
}
# bind double quote:
ascii 0x22 <s> smartDQuote TeX
proc smartQuote {} {
global TeXmodeVars
if {[isSelection]} { deleteSelection }
if { !$TeXmodeVars(smartQuotes) || [literalChar] } { insertText {'}; return }
if {[leftQ]} {
insertText {`}
} else {
insertText {'}
}
}
# bind single quote:
ascii 0x27 smartQuote TeX
proc leftQ {} {
if { [getPos] == 0 } { return 1 };
set q [lookAt [expr [getPos]-1]]
case $q in {
{\t} {return 1}
{(} {return 1}
{\{} {return 1}
{[} {return 1}
{<} {return 1}
{\ } {return 1}
{\r} {return 1}
}
return 0
}
#--------------------------------------------------------------------------
# Smart dots:
#--------------------------------------------------------------------------
proc smartDots {} {
global TeXmodeVars
if {[isSelection]} { deleteSelection }
if { !$TeXmodeVars(smartDots) || [literalChar] } { insertText {.}; return }
if {[lookAt [expr [set endPos [getPos]]-1]] == "."} then {
if {[lookAt [set begPos [expr $endPos-2]]] == "."} then {
replaceText $begPos $endPos "\\ldots"
} else {
insertText "."
}
} else {
insertText "."
}
}
# bind period:
ascii 0x2e smartDots "TeX"
#--------------------------------------------------------------------------
# Smart subscripts and superscripts:
#--------------------------------------------------------------------------
proc smartSubscripts {} {
smartScripts {_}
}
proc smartSuperscripts {} {
smartScripts {^}
}
proc smartScripts {char} {
global TeXmodeVars
if {[isSelection]} { deleteSelection }
if { !$TeXmodeVars(smartScripts) || [literalChar] } then {
insertText $char
return
}
if { $TeXmodeVars(smartScripts) } then {
if { $char == {_} } {subscript} {superscript}
}
}
# bind underscore and caret:
ascii 0x5f <s> smartSubscripts "TeX"
ascii 0x5e <s> smartSuperscripts "TeX"
#--------------------------------------------------------------------------
# Escapes and exceptions:
#--------------------------------------------------------------------------
# proc literalChar {} {
# return [expr {[lookAt [expr [getPos] - 1]] == "\\"}]
# }
#
proc escapeSmartStuff {} {
if {![isSelection]} then {
set pos [getPos]
# Escape double quotes:
if { $pos > 1 } then {
set pos2 [expr $pos - 2]
if { [getText $pos2 $pos] == "''" } then {
replaceText $pos2 $pos {"}
return
} elseif { [getText $pos2 $pos] == "``" } then {
replaceText $pos2 $pos {"}
return
}
}
# Escape single quote:
if { $pos > 0 } then {
set pos1 [expr $pos - 1]
if { [lookAt $pos1] == "`" } then {
backSpace
insertText {'}
return
}
}
# Escape dots:
if { $pos > 5 } then {
set pos6 [expr $pos - 6]
if { [getText $pos6 $pos] == "\\ldots" } then {
replaceText $pos6 $pos {...}
return
}
}
# Escape underscore:
if { $pos > 1 && [maxPos] > [expr $pos + 1] } then {
set begPos [expr $pos - 2]
set endPos [expr $pos + 2]
if { [getText $begPos $endPos] == "_\{\}Ñ" } then {
replaceText $begPos $endPos {_}
return
}
}
# Escape caret:
if { $pos > 1 && [maxPos] > [expr $pos + 1] } then {
set begPos [expr $pos - 2]
set endPos [expr $pos + 2]
if { [getText $begPos $endPos] == "^\{\}Ñ" } then {
replaceText $begPos $endPos {^}
return
}
}
}
backSpace
}
# bind delete key:
ascii 0x08 escapeSmartStuff "TeX"